import java.text.SimpleDateFormat
import java.util.*
import java.util.stream.Collectors

/**
 * 基础
 */
data class User(var name: String?, var age: Int?) {


}


fun main() {


    run {
        val dt = "2022-02-21 12:12:12"
        val dt1 = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dt)



        val formatDay = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA)
        println(formatDay.format(Date()).toString())


        val u1 = User("a", 1)
        val u2 = User("b", 2)
        val u3 = User("a", 3)
        val users = arrayListOf<User>(u1, u2, u3)
        val uc = users.stream().map(User::name).collect(Collectors.toList())
        println(uc[0].toString())


        //基本数据类型(b,s,i,l,f,d,c,b)
        val a: Byte = 0
        val b: Short = 1
        val c: Int = 2
        val d: Long = 3L
        val e: Float = 0.1f
        val f: Double = 0.2
        val g: Char = 'a'
        val h: Boolean = true

        //toByte()/toShort()...数字类型转换
        val toChar = a.toChar()

        //shl(bits)有符号左移,shr有符号右移,ushr无符号右移,and位与,or位或,xor位异或,inv位非

        //||,&&,!

        //if,when,for,while,do...while
        val names = arrayListOf("akali", "annie", "ashe")
        names.contains("")
        //if else即?:三元运算符
        if (0 == names.size) println("names size=0") else println("names size!=0")
        when (names.size) {
            0 -> println("names size=0")
            1 -> println("names size=1")
            2 -> println("names size=2")
            else -> println("names size=else")
        }
        for (name in names) println("name:$name")
        for ((index, value) in names.withIndex()) println("$index name:$value")
        for (i in 1..4 step 2) println("i:$i")
        var i = 0
        while (i < names.size) {
            println("name:${names[i]}")
            i++
        }
        var j = 0
        do {
            println("name:${names[j]}")
            j++
        } while (j < names.size)

        //break,continue
        outer@ for (i in 1..10) {
            inner@ for (j in 3..6) {
                if (4 == j) continue@inner
                if (5 == j) break@outer
            }
        }
        //返回到标签而不是退出整个函数(下三方法效果相同)
        fun it1() {
            listOf(1, 2, 3, 4).forEach lit@{
                if (3 == it) return@lit//return@forEach也可
                println("it:$it")
            }
            println("iterator1 end")
        }

        //返回到标签而不是退出整个函数
        fun it2() {
            listOf(1, 2, 3, 4).forEach {
                if (3 == it) return@forEach
                println("it:$it")
            }
            println("iterator2 end")
        }

        //使用匿名函数return即退出该匿名函数
        fun it3() {
            listOf(1, 2, 3, 4).forEach(fun(value: Int) {
                if (3 == value) return
                println("it:$value")
            })
            println("iterator3 end")
        }
        it1()
        it2()
        it3()
    }
}


class Basement {
}
